package com.truyen.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.truyen.service.JsoupService;

@Controller
@RequestMapping("/jsoup")
public class JsoupController {
	
	@Autowired
	private JsoupService jsoupService;
	
	private boolean flagGetBlogTruyen = true;
	private boolean flagGetTruyenKiemHiepHixxinfo = true;
	private boolean flagGetTruyenTrinhThamHixxinfo = true;
	private boolean flagGetTruyenTinhCamHixxinfo = true;
	private boolean flagGetTruyenMaTheGioiMa = true;
	
	/********************************************************************
	 * 
	 * lay truyen tu blogtruyen
	 * 
	 *********************************************************************/
	
	// lay truyen tu blog truyen
	@RequestMapping("/lay-truyen-tu-blogTruyen.htm")
	public String getLinkSourceAllTruyenFromBlogTruyen() {
		if(flagGetBlogTruyen){
			flagGetBlogTruyen = false;
			jsoupService.getLinkSourceAllTruyenFromBlogTruyen("TatCa");
			flagGetBlogTruyen = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	// cap nhat hinh anh va lst chapter tu blogtruyen
	@RequestMapping("/cap-nhat-truyen-tu-blogTruyen.htm")
	public String getImagevLstChapterOfComicBlogTruyen() {
		if(flagGetBlogTruyen){
			flagGetBlogTruyen = false;
			jsoupService.getImagevLstChapterOfComicBlogTruyen();
			flagGetBlogTruyen = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//cap nhat danh sach chapter cua comic tu blog truyen
	@RequestMapping("/cap-nhat-chapter-comic-tu-blogTruyen.htm")
	public String getContentChapterOfComicBlogTruyen() {
		if(flagGetBlogTruyen){
			flagGetBlogTruyen = false;
			jsoupService.getContentChapterOfComicBlogTruyen();
			flagGetBlogTruyen = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	/********************************************************************
	 * 
	 * lay truyen kiem hiep tu hixx.info
	 * 
	 *********************************************************************/
	//lay truyen tu hixx.info
	@RequestMapping("/lay-truyen-kiem-hiep-tu-hixx.htm")
	public String getLinkSourceTruyenKiemHiepFromHixx() {
		if(flagGetTruyenKiemHiepHixxinfo){
			flagGetTruyenKiemHiepHixxinfo = false;
			jsoupService.getLinkSourceTruyenKiemHiepFromHixx();
			flagGetTruyenKiemHiepHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay anh truyen, thong tin va danh sach chuong tu hixx.info
	@RequestMapping("/cap-nhat-truyen-kiem-hiep-tu-hixx.htm")
	public String getImageInfoChapterTruyenKiemHiepFromHixx() {
		if(flagGetTruyenKiemHiepHixxinfo){
			flagGetTruyenKiemHiepHixxinfo = false;
			jsoupService.getImageInfoChapterTruyenKiemHiepFromHixx();
			flagGetTruyenKiemHiepHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay noi dung cac chuong tu hixx.info
	@RequestMapping("/cap-nhat-content-chapter-truyen-kiem-hiep-tu-hixx.htm")
	public String getContentChapterTruyenKiemHiepFromHixx() {
		if(flagGetTruyenKiemHiepHixxinfo){
			flagGetTruyenKiemHiepHixxinfo = false;
			jsoupService.getContentChapterTruyenKiemHiepFromHixx();
			flagGetTruyenKiemHiepHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	/********************************************************************
	 * 
	 * lay truyen trinh tham tu hixx.info
	 * 
	 *********************************************************************/
	//lay truyen tu hixx.info
	@RequestMapping("/lay-truyen-trinh-tham-tu-hixx.htm")
	public String getLinkSourceTruyenTrinhThamFromHixx() {
		if(flagGetTruyenTrinhThamHixxinfo){
			flagGetTruyenTrinhThamHixxinfo = false;
			jsoupService.getLinkSourceTruyenTrinhThamFromHixx();
			flagGetTruyenTrinhThamHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay anh truyen, thong tin va danh sach chuong tu hixx.info
	@RequestMapping("/cap-nhat-truyen-trinh-tham-tu-hixx.htm")
	public String getImageInfoChapterTruyenTrinhThamFromHixx() {
		if(flagGetTruyenTrinhThamHixxinfo){
			flagGetTruyenTrinhThamHixxinfo = false;
			jsoupService.getImageInfoChapterTruyenTrinhThamFromHixx();
			flagGetTruyenTrinhThamHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay noi dung cac chuong tu hixx.info
	@RequestMapping("/cap-nhat-content-chapter-truyen-trinh-tham-tu-hixx.htm")
	public String getContentChapterTruyenTrinhThamFromHixx() {
		if(flagGetTruyenTrinhThamHixxinfo){
			flagGetTruyenTrinhThamHixxinfo = false;
			jsoupService.getContentChapterTruyenTrinhThamFromHixx();
			flagGetTruyenTrinhThamHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	/********************************************************************
	 * 
	 * lay truyen kiem hiep tu hixx.info
	 * 
	 *********************************************************************/
	//lay truyen tu hixx.info
	@RequestMapping("/lay-truyen-tinh-cam-tu-hixx.htm")
	public String getLinkSourceTruyenTinhCamFromHixx() {
		if(flagGetTruyenTinhCamHixxinfo){
			flagGetTruyenTinhCamHixxinfo = false;
			jsoupService.getLinkSourceTruyenTinhCamFromHixx();
			flagGetTruyenTinhCamHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay anh truyen, thong tin va danh sach chuong tu hixx.info
	@RequestMapping("/cap-nhat-truyen-tinh-cam-tu-hixx.htm")
	public String getImageInfoChapterTruyenTinhCamFromHixx() {
		if(flagGetTruyenTinhCamHixxinfo){
			flagGetTruyenTinhCamHixxinfo = false;
			jsoupService.getImageInfoChapterTruyenTinhCamFromHixx();
			flagGetTruyenTinhCamHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay noi dung cac chuong tu hixx.info
	@RequestMapping("/cap-nhat-content-chapter-truyen-tinh-cam-tu-hixx.htm")
	public String getContentChapterTruyenTinhCamFromHixx() {
		if(flagGetTruyenTinhCamHixxinfo){
			flagGetTruyenTinhCamHixxinfo = false;
			jsoupService.getContentChapterTruyenTinhCamFromHixx();
			flagGetTruyenTinhCamHixxinfo = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	/********************************************************************
	 * 
	 * lay truyen ma tu yeutruyen.vn
	 * 
	 *********************************************************************/
	
	//lay truyen ma tu yeutruyen.vn
	@RequestMapping("/lay-truyen-ma.htm")
	public String getLinkSourceTruyenMa() {
		if(flagGetTruyenMaTheGioiMa){
			flagGetTruyenMaTheGioiMa = false;
			jsoupService.getLinkSourceTruyenMa();
			flagGetTruyenMaTheGioiMa = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay noi dung cac chuong tu yeutruyen.vn
	@RequestMapping("/cap-nhat-content-chapter-truyen-ma.htm")
	public String getContentChapterTruyenMa() {
		if(flagGetTruyenMaTheGioiMa){
			flagGetTruyenMaTheGioiMa = false;
			jsoupService.getContentChapterTruyenMa();
			flagGetTruyenMaTheGioiMa = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	/********************************************************************
	 * 
	 * lay truyen ma tu thegioima.com
	 * 
	 *********************************************************************/
	
	//lay truyen ma tu thegioima.com
	@RequestMapping("/lay-truyen-ma-TGM.htm")
	public String getLinkSourceTruyenMaTGM() {
		if(flagGetTruyenMaTheGioiMa){
			flagGetTruyenMaTheGioiMa = false;
			jsoupService.getLinkSourceTruyenMaTGM();
			flagGetTruyenMaTheGioiMa = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay noi dung cac chuong tu thegioima.com
	@RequestMapping("/cap-nhat-content-chapter-truyen-ma-TGM.htm")
	public String getContentChapterTruyenMaTGM() {
		if(flagGetTruyenMaTheGioiMa){
			flagGetTruyenMaTheGioiMa = false;
			jsoupService.getContentChapterTruyenMaTGM();
			flagGetTruyenMaTheGioiMa = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay noi dung cac chuong tu thegioima.com
	@RequestMapping("/cap-nhat-content-chapter-tam-truyen-ma-TGM.htm")
	public String getContentChapterTamTruyenMaTGM() {
		if(flagGetTruyenMaTheGioiMa){
			flagGetTruyenMaTheGioiMa = false;
			jsoupService.getContentChapterTamTruyenMaTGM();
			flagGetTruyenMaTheGioiMa = true;
		}
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	/********************************************************************
	 * 
	 * lay anh dep hoanvu.net
	 * 
	 *********************************************************************/
	//lay anh dep
	@RequestMapping("/lay-anh-dep.htm")
	public String getLinkAlbum() {
		jsoupService.getLinkAlbum();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//lay content 
	@RequestMapping("/cap-nhat-content-anh-dep.htm")
	public String updateAlbum() {
		jsoupService.updateAlbum();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	//ngung lay anh
	@RequestMapping("/ngung-lay-content-anh-dep.htm")
	public String stopUpdateAlbum() {
		jsoupService.stopUpdateAlbum();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	/********************************************************************
	 * 
	 * cap nhat the loai truyen chu
	 * 
	 *********************************************************************/
	
	@RequestMapping("/lay-link-category-truyen-kiem-hiep.htm")
	public String getCategoryTruyenKiemHiepFromTungHoanh() {
		jsoupService.getCategoryTruyenKiemHiepFromTungHoanh();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	@RequestMapping("/lay-link-category-truyen-tinh-cam.htm")
	public String getCategoryTruyenTinhCamFromTungHoanh() {
		jsoupService.getCategoryTruyenTinhCamFromTungHoanh();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	@RequestMapping("/lay-link-category-truyen-trinh-tham.htm")
	public String getCategoryTruyenTrinhThamFromTungHoanh() {
		jsoupService.getCategoryTruyenTrinhThamFromTungHoanh();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	@RequestMapping("/cap-nhat-category-truyen-kiem-hiep.htm")
	public String getCategoryTruyenKiemHiepByLinkFromTungHoanh() {
		jsoupService.getCategoryTruyenKiemHiepByLinkFromTungHoanh();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	@RequestMapping("/cap-nhat-category-truyen-tinh-cam.htm")
	public String getCategoryTruyenTinhCamByLinkFromTungHoanh() {
		jsoupService.getCategoryTruyenTinhCamByLinkFromTungHoanh();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
	@RequestMapping("/cap-nhat-category-truyen-trinh-tham.htm")
	public String getCategoryTruyenTrinhThamByLinkFromTungHoanh() {
		jsoupService.getCategoryTruyenTrinhThamByLinkFromTungHoanh();
		return "redirect:/quan-ly/tai-khoan/tao-tai-khoan.htm";
	}
	
}
